import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/Home.vue'
import Layout from '../layout/Layout.vue'
import store from '../store/index'

Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      redirect: '/index/home'
    },
    {  // 布局
      path: '/index',
      name: 'Index',
      component: Layout,
      // redirect: '/index/home',
      children: [
        // 首页
        // 智慧停车
        {
          path: 'home',
          name: 'Home',
          component: Home,
          meta: {
            title: '智慧停车',
            icon: ''
          },
        },
        // 停车记录
        {
          path: 'parkrecord',
          name: 'ParkRecord',
          component: () => import('../views/home/ParkingRecord/ParkRecord.vue'), 
          meta: {
            title: '停车记录',
            icon: ''
          },
        },
        // 收费记录
        {
          path: 'receivRecord',
          name: 'ReceivRecord',
          component: () => import('../views/home/ReceivRecord.vue'),
          meta: {
            title: '收费记录',
            icon: ''
          },
        },
          
        // 查看警员 - constable
        {
          path: 'constable',
          name: 'Constable',
          component: () => import('../views/constable/Constable.vue'),
          meta: {
            title: '查看警员',
            icon: 'icon1'
          },
          children: [
            {
              path: 'constable1',
              name: 'Constable1',
              component: () => import('../views/constable/Constable1.vue'),
              meta: {
                title: '警员列表',
                icon: ''
              },
            },
            
          ]
        },
        // 我的警情 - alert
        {
          path: 'alert',
          name: 'Alert',
          component: () => import('../views/alert/Alert.vue'),
          meta: {
            title: '我的警情',
            icon: '../assets/images/icon3_line.png'
          },
          children: [
            {
              path: 'alertsList',
              name: 'AlertsList',
              component: () => import('../views/alert/AlertsList.vue'),
              meta: {
                title: '警情列表',
                icon: ''
              },
            },
            {
              path: 'historyAlerts',
              name: 'HistoryAlerts',
              component: () => import('../views/alert/HistoryAlerts.vue'),
              meta: {
                title: '历史警情',
                icon: ''
              },
            },
          ]
        },
        // 交通概况
        {
          path: 'traffic',
          name: 'Traffic',
          component: () => import('../views/traffic/Traffic.vue'),
          meta: {
            title: '交通概况',
            icon: '../assets/images/icon4_line.png'
          },
          children: [
            {
              path:'index',
              name:'Index',
              component:()=>import('../views/traffic/Traffic.vue'),
              meta: {
                title: '交通指数',
                icon: ''
              },
            }
          ]
        },
        // 安全中心 - safety
        {
          path: 'safety',
          name: 'Safety',
          component: () => import('../views/safety/Safety.vue'),
          meta: {
            title: '安全中心',
            icon: '../assets/images/icon5_line.png'
          },
          // children: []
        },
        // 违章查询 - TrafficViolations
        {
          path: 'trafficViolations',
          name: 'TrafficViolations',
          component: () => import('../views/trafficViolations/TrafficViolations.vue'),
          meta: {
            title: '违章查询',
            icon: '../assets/images/icon6_line.png'
          },
          // children: []
        },
        // 帮助中心 - Help
        {
          path: 'help',
          name: 'Help',
          component: () => import('../views/help/Help.vue'),
          meta: {
            title: '帮助中心',
            icon: '../assets/images/icon7_line.png'
          },
          // children: []
        },
      ]
    },
    {
      path:'/login',
      name:'Login',
      component:()=>import('../views/Login.vue')
    },
    {
      path:'*',
      name:'Notfind',
      component:()=>import('../components/Notfind.vue')
    }
    
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{

  store.commit('setRoutes', routes)
  next()
})

export default router

